package com.rui.study.micro.usermanager.mapper;

import com.rui.study.micro.usermanager.entity.UserInfo;
import org.apache.ibatis.annotations.*;

public interface UserMapper {

    @Results(id = "userInfo", value = {
            @Result(property = "username.email", column = "email"),
            @Result(property = "username.phoneNumber", column = "phone_number"),
            @Result(property = "username.name", column = "name"),
    })
    @Insert("INSERT INTO user_info (" +
            "    email," +
            "    phone_number," +
            "    name," +
            "    password," +
            "    head_portraint," +
            "    status)" +
            "VALUES (" +
            "    #{username.email}," +
            "    #{username.phoneNumber}," +
            "    #{username.name}," +
            "    #{password}," +
            "    #{headPortraint}," +
            "    #{status})")
    int insertUserInfo(UserInfo userInfo);

   @Select("SELECT " +
            "   user_id," +
            "   email," +
            "   phone_number," +
            "   name," +
            "   password," +
            "   head_portraint," +
            "   create_date," +
            "   status " +
            "FROM " +
            "   user_info " +
            "WHERE " +
            "   (email = #{username} OR phone_number = #{username} OR name = #{username}) " +
            "LIMIT 1")
     UserInfo selectUserInfo(String username);


    @Select("SELECT user_id " +
            "FROM " +
            "   user_info " +
            "WHERE " +
            "   (email = #{username} OR phone_number = #{username} OR name = #{username}) " +
            "LIMIT 1")
    Long selectUserId(String username);
}
